//
// Created by bleedingfight on 2020/7/5.
//

#include "isHappy.h"

bool isHappy(int n) {
    int result = 0;
    std::set<int> current_num;
    while (n != 1 && current_num.count(n) == 0) {
        current_num.insert(n);
        while (n) {
            int res = n % 10;
            result += res * res;
            n /= 10;
        }

        n = result;
        result = 0;
    }
    if (n == 1)
        return true;
    else
        return false;

}